﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using PluginInterFace;

namespace PickExperts2.form
{
    public partial class fmAddData : Form
    {
        public fmAddData()
        {
            InitializeComponent();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.OK;
            this.Close();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            string[] tmp;
            string[] str;
            string strtmp;
            int i;
            PluginInterFace.Model.ssq[] mss;
            PluginInterFace.BLL.ssq bs = new PluginInterFace.BLL.ssq();
            if (textBox1.Text != "")
            {
                // 从字符串导入
                tmp = textBox1.Lines;
                mss = new PluginInterFace.Model.ssq[tmp.Length];
                for (i = 0; i < tmp.Length; i++)
                {
                    mss[i] = new PluginInterFace.Model.ssq();
                    strtmp = tmp[i].Replace('\t', ' ');
                    if (strtmp.IndexOf('(') >= 0)
                        strtmp = strtmp.Remove(strtmp.LastIndexOf("("), strtmp.LastIndexOf(")") - strtmp.LastIndexOf("(") + 2);
                    str = strtmp.Split(' ');
                    mss[i].日期 = str[0];
                    mss[i].期号 = int.Parse(str[1]);
                    //MessageBox.Show(str[0] + "|" + str[1] + "|" + str[2] + "|" + str[3] + "|" + str[4] + "|" + str[5] + "|" + str[6] + "|" + str[7] + "|" + str[8] + "|" + str[9] + "|" + str[10] + "|" + str[11]);
                    mss[i].红1 = byte.Parse(str[2]);
                    mss[i].红2 = byte.Parse(str[3]);
                    mss[i].红3 = byte.Parse(str[4]);
                    mss[i].红4 = byte.Parse(str[5]);
                    mss[i].红5 = byte.Parse(str[6]);
                    mss[i].红6 = byte.Parse(str[7]);
                    mss[i].蓝 = byte.Parse(str[8]);
                    mss[i].销售额 = int.Parse(str[9].Replace(",", ""));
                    mss[i].一等奖 = int.Parse(str[10]);
                    mss[i].二等奖 = int.Parse(str[11]);
                }
                bs.AddData(mss);

                MessageBox.Show("数据导入完成", "消息");
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            string[] tmp;
            string[] str;
            string strtmp;
            int i, j;
            tmp = textBox1.Lines;
            for (i = 0; i < tmp.Length; i++)
            {
                strtmp = tmp[i].Replace('\t', ' ');
                if (strtmp.IndexOf('(') >= 0)
                    strtmp = strtmp.Remove(strtmp.LastIndexOf("("), strtmp.LastIndexOf(")") - strtmp.LastIndexOf("(") + 2);
                str = strtmp.Split(' ');
                tmp[i] = str[0] + " " + str[1] + " ";
                for (j = 0; j < str[2].Length; j += 2)
                {
                    tmp[i] += str[2].Substring(j, 2) + " ";
                }
                tmp[i] += str[3] + " " + str[4] + " " + str[5];
            }
            textBox1.Text = "";
            for (i = 0; i < tmp.Length; i++)
            {
                textBox1.Text += tmp[i];
                if (i + 1 != tmp.Length)
                    textBox1.Text += "\r\n";
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            textBox1.Text = "";
        }
    }
}
